package com.text.day2_5.homework;

/**
 * 替换字符串的叠字
 * 例如，对于字符串 "hello nice to meet you"
 * 将其中出现两次的字符 ll 和 ee 分别替换为 l~ 和 e~
 * 输出为：hel~o nice to me~t you
 *"浩浩荡荡"
 * 输出为： 浩~荡~
 */
public class Home2 {

    public static void main(String[] args) {
        String s = "hello nice to meet you";
        String r = dealStr(s);
        System.out.println(r);
    }

    public static String dealStr(String s) {
        char[] c = s.toCharArray();
        for (int i = 1; i < c.length; i++) {
            if (c[i] == c[i-1]) {
                c[i] = '~';
                i += 2;
            }
        }
        return new String(c,0,c.length);
    }

}
